| Conditions | 2 |
| Total Lines | 60 |
| Code Lines | 53 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import { stopLocationUpdatesAsync } from 'expo-location'; |
||
| 9 | |||
| 10 | export default function Wallet({navigation}): any { |
||
| 11 | const [history, setHistory] = useState([]); |
||
| 12 | const [modalVisible, setModalVisible] = useState(false); |
||
| 13 | const [currentJourney, setCurrentJourney] = useState(null); |
||
| 14 | |||
| 15 | // Get balance for logged in user |
||
| 16 | useEffect(() => { |
||
| 17 | async function getHistory(): Promise<void> { |
||
| 18 | const result = await userModel.getHistory(); |
||
| 19 | setHistory(result); |
||
| 20 | |||
| 21 | }; |
||
| 22 | getHistory(); |
||
| 23 | }, []); |
||
| 24 | |||
| 25 | return ( |
||
| 26 | <View style={styles.container}> |
||
| 27 | |||
| 28 | <View style={[styles.infoContainer]}> |
||
| 29 | <Pressable style={[styles.backButton, styles.shadowProp]} onPress={() => navigation.navigate('Map')}> |
||
| 30 | <Icon |
||
| 31 | name='x' |
||
| 32 | size={25} |
||
| 33 | color='black' |
||
| 34 | /> |
||
| 35 | </Pressable> |
||
| 36 | |||
| 37 | <Text style={styles.title}>Ride History</Text> |
||
| 38 | </View> |
||
| 39 | |||
| 40 | <ScrollView style={styles.prepaidContainer}> |
||
| 41 | {history.map((h, index) => ( |
||
| 42 | <Pressable onPress={() => { |
||
| 43 | setCurrentJourney(h) |
||
| 44 | setModalVisible(true) |
||
| 45 | }} |
||
| 46 | key={index} |
||
| 47 | > |
||
| 48 | <View style={styles.rideHistory}> |
||
| 49 | |||
| 50 | <View style={styles.primaryInfo}> |
||
| 51 | <Text style={styles.textDistance}> |
||
| 52 | {mapModel.calcDistance(h.startPosition[0], h.startPosition[1], h.endPosition[0], h.endPosition[1])} km / {h.totalMin} min |
||
| 53 | </Text> |
||
| 54 | <Text style={styles.textCost}>{h.totalPrice} kr</Text> |
||
| 55 | </View> |
||
| 56 | |||
| 57 | <View style={styles.secondaryInfo}> |
||
| 58 | <Text style={styles.textDate}>{h.date}</Text> |
||
| 59 | </View> |
||
| 60 | </View> |
||
| 61 | </Pressable> |
||
| 62 | ))} |
||
| 63 | </ScrollView> |
||
| 64 | |||
| 65 | |||
| 66 | <HistoryMap navigation={navigation} journey={currentJourney} modalVisible={modalVisible} setModalVisible={setModalVisible}></HistoryMap> |
||
| 67 | |||
| 68 | </View> |
||
| 69 | ) |
||
| 236 | }); |